package lec07datastructure.v2;

public class MyStack {
    private static final int DEFAULT_SIZE = 100;
    int[] data = new int[DEFAULT_SIZE];
    int top = -1;

    public static void main(String[] args) {
        MyStack s = new MyStack();
        for (int i = 0; i < 10; i++) {
            s.push(i);
        }
        while (s.top != -1) {
            System.out.println(s.peek());
            s.pop();
        }
    }

    void push(int x) {
        if (top == data.length - 1) {
            int[] data1 = new int[data.length * 2];
            System.arraycopy(data, 0, data1, 0, data.length);
            data = data1;
        }
        data[++top] = x;
    }

    int peek() {
        if (top != -1)
            return data[top];
        return -1;
    }

    void pop() {
        if (top != -1)
            --top;
    }

}
